package com.cloudsigns.factorymanager2.project.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringInstallationOrderBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by tony on 2017/12/11.
 */

public class EngineeringInformationAdapter extends BaseAdapter {
    private Context context;
    private List<EngineeringInstallationOrderBean> datas = new ArrayList<EngineeringInstallationOrderBean>();
    private LayoutInflater inflater;
    private String tag = "";


    public EngineeringInformationAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;
    }

    public void setData(List<EngineeringInstallationOrderBean> list) {
        this.datas.clear();
        if (null != list) {
            this.datas.addAll(list);
        }

    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public EngineeringInstallationOrderBean getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final EngineeringInformationAdapter.ViewHolder holder;
        if (convertView == null) {
            holder = new EngineeringInformationAdapter.ViewHolder();

            convertView = inflater.inflate(R.layout.item_add_engineering_information_lv, null);
            holder.tv_up = convertView.findViewById(R.id.tv_up);
            holder.tv_down = convertView.findViewById(R.id.tv_down);
            holder.img_right = convertView.findViewById(R.id.img_right);
            holder.img_left = convertView.findViewById(R.id.img_left);


            convertView.setTag(holder);
        } else {
            holder = (EngineeringInformationAdapter.ViewHolder) convertView.getTag();
        }
        EngineeringInstallationOrderBean engineeringBean = datas.get(position);
        if (null != engineeringBean) {
            holder.tv_up.setText(engineeringBean.getEngineeringName());
            holder.tv_down.setText(engineeringBean.getEngineeringAddress());
        }

        if (tag.equals("BatchInstallationOrderDetailActivity")) {
            holder.img_right.setBackgroundResource(R.mipmap.icon_edit);
        } else if (tag.equals("ReceiveEngineeringBatchInstallationOrderAcitivity")) {
           // holder.img_right.setBackgroundResource(R.mipmap.arrow_down_icon);
        } else if (tag.equals("ReceiveEngineeringConstructOrderActivity")) {

        } else {
           // holder.img_right.setBackgroundResource(R.mipmap.icon_arrow_right);
        }
        holder.img_right.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        return convertView;
    }

    private class ViewHolder {
        private TextView tv_up;
        private TextView tv_down;
        private ImageView img_right;
        private ImageView img_left;
    }
}
